<template>
  <div class="main-card">
    <div class="main-card-left">
      <div class="right-card">
        <h3>好友管理说明</h3>
        <ul class="helper-list">
          <li>可通过手机号/昵称搜索添加好友。</li>
          <li>支持删除、拉黑好友操作。</li>
          <li>请文明交友，遵守平台规范。</li>
        </ul>
        <div class="history-section">
          <h4>历史操作</h4>
          <ul class="history-list">
            <li v-for="(item, idx) in history" :key="idx">{{ item }}</li>
            <li v-if="!history || history.length === 0">暂无历史</li>
          </ul>
        </div>
      </div>
    </div>
    <div class="main-card-right">
      <h2>好友管理</h2>
      <div class="search-bar">
        <input v-model="searchName" placeholder="输入用户名搜索添加好友" />
        <button class="primary-btn" @click="addFriend">添加好友</button>
      </div>
      <div class="friend-list">
        <h3>我的好友</h3>
        <div v-if="friends.length === 0" class="empty">暂无好友</div>
        <div v-for="item in friends" :key="item.id" class="friend-item">
          <span>{{ item.name }}</span>
          <button class="danger-btn" @click="removeFriend(item.id)">删除</button>
          <button class="black-btn" @click="blackFriend(item.id)">拉黑</button>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref } from 'vue'
const searchName = ref('')
const friends = ref([
  { id: 1, name: '小明' },
  { id: 2, name: '小红' },
])
const blacks = ref([
  // { id: 3, name: '小刚' },
])
function addFriend() {
  if (!searchName.value.trim()) return alert('请输入用户名')
  if (friends.value.find(f => f.name === searchName.value)) return alert('已是好友')
  if (blacks.value.find(f => f.name === searchName.value)) return alert('该用户已被拉黑')
  friends.value.push({ id: Date.now(), name: searchName.value })
  searchName.value = ''
}
function removeFriend(id) {
  friends.value = friends.value.filter(f => f.id !== id)
}
function blackFriend(id) {
  const friend = friends.value.find(f => f.id === id)
  if (friend) {
    blacks.value.push(friend)
    friends.value = friends.value.filter(f => f.id !== id)
  }
}
</script>
<style scoped>
.main-card {
  flex-direction: row !important;
  display: flex;
  gap: 36px;
  max-width: 1100px;
  margin: 40px auto;
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 4px 32px rgba(37, 99, 235, 0.10);
  padding: 40px 32px;
  align-items: stretch;
}
.main-card-left {
  min-width: 320px;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  background: #f7faff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(37,99,235,0.06);
  padding: 24px 18px 18px 18px;
}
.main-card-right {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-width: 320px;
}
.right-card {
  background: #f7faff;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(37,99,235,0.06);
  padding: 24px 18px 18px 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}
.friend-list, .black-list {
  margin-bottom: 18px;
}
.friend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.danger-btn {
  background: #e74c3c;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
}
.black-btn {
  background: #888;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
}
.empty {
  color: #aaa;
  margin: 8px 0;
}
.helper-section {
  margin-top: 24px;
  background: #f1f5ff;
  border-radius: 8px;
  padding: 12px 14px;
}
.helper-section h4 {
  color: #2563eb;
  font-size: 1em;
  margin-bottom: 6px;
}
.helper-list {
  padding-left: 18px;
  color: #555;
  font-size: 0.98em;
  margin: 0;
}
.history-section {
  margin-top: 24px;
  background: #f1f5ff;
  border-radius: 8px;
  padding: 12px 14px;
}
.history-list {
  padding-left: 18px;
  color: #555;
  font-size: 0.98em;
  margin: 0;
}
@media (max-width: 900px) {
  .main-card {
    flex-direction: column;
    padding: 24px 8px;
  }
  .main-card-left, .main-card-right {
    width: 100%;
    min-width: 0;
  }
}
</style> 